const { feedbackInter } = require("../../data/Interface")
const { errToast } = require("../actionCreator")

const addfeedback = (user_id, feedback_context) => {
    return (dispatch) => {
        let url = `${feedbackInter}`
        fetch(url, {
            method: 'POST',
            mode: 'cors',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({
                user_id: `${user_id}`,
                feedback_context: `${feedback_context}`
            })
        }).then((res) => {
            return res.json()
        }).then(() => {
            errToast('反馈成功')
            dispatch({
                type: 'ADD_FEEDBACK',
                value: feedback_context,
                index: user_id
            })
        }).catch((err) => {
            console.log(err)
        })
    }
}
const addfeedbackbus = (business_id, feedback_context) => {
    return (dispatch) => {
        let url = `${feedbackInter}`
        fetch(url, {
            method: 'POST',
            mode: 'cors',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({
                business_id: `${business_id}`,
                feedback_context: `${feedback_context}`
            })
        }).then((res) => {
            return res.json()
        }).then(() => {
            errToast('反馈成功')
            dispatch({
                type: 'ADD_FEEDBACK',
                value: feedback_context,
                index: business_id
            })
        }).catch((err) => {
            console.log(err)
        })
    }
}
export {addfeedback,addfeedbackbus};